local ClientOHOH = _G.ClientOHOH;
local M = ClientOHOH.class.new(script, ClientOHOH.files.OHOHScreenBase());
local CallBackManager = ClientOHOH.load.CallBackManager();
local CommonOHOH =_G.CommonOHOH;
local LanguageHelper=_G.LanguageHelper;
local BigNumberHelper = ClientOHOH.load.BigNumberHelper();
local ConnectClass = _G.CommonOHOH.load.Connect();
local BtnHelper = ClientOHOH.load.BtnHelper();
function InitInsts(ui)
    ui.insts = {};
    ui.insts.Close = "Frame.Frame.close";
    ui.insts.root = "Frame.Frame";

    ui.insts.Spin = "Frame.Frame.Spin";
    ui.insts.SpinLable = "Frame.Frame.Spin.TextLabel";
    ui.insts.SpinCount = "Frame.Frame.Spin.off";

    ui.insts.LeftSpinBuy = "Frame.Frame.Buy3";
    ui.insts.LeftSpinBuyLable="Frame.Frame.Buy3.TextLabel";
    ui.insts.LeftSpinBuyIcon="Frame.Frame.Buy3.Icon";
    ui.insts.LeftSpinBuyCount="Frame.Frame.Buy3.off";

    ui.insts.RightSpinBuy = "Frame.Frame.Buy10";
    ui.insts.RightSpinBuyLable="Frame.Frame.Buy10.TextLabel";
    ui.insts.RightSpinBuyIcon="Frame.Frame.Buy10.Icon";
    ui.insts.RightSpinBuyCount="Frame.Frame.Buy10.off";

    ui.insts.TimeCountDown="Frame.Frame.TextLabel";

    ui.insts.Center = "Frame.Frame.Progress.Center";
    ui.insts.content ={};
    for i=1,5 do
        ui.insts.content[i]={
            Cell="Frame.Frame.Progress.Center."..i,
            CellFrame="Frame.Frame.Progress.Center."..i..".Frame",
            viewPort="Frame.Frame.Progress.Center."..i..".Frame.Viewport",
            CF="Frame.Frame.Progress.Center."..i..".Frame.Viewport.CF",
            Icon="Frame.Frame.Progress.Center."..i..".Frame.Icon",
            Probability="Frame.Frame.Progress.Center."..i..".Frame.Increment",
            Name="Frame.Frame.Progress.Center."..i..".Frame.name",
            BgColor="Frame.Frame.Progress.Center."..i..".Background",
        }
    end

end;
function M.MobileSize(self)
	if _G.client.IsMobile then --是移动设备
		if self.insts.root then
			local pos= self.insts.root:GetAttribute("Position")
			local size=self.insts.root:GetAttribute("Size")

			if pos then
				self.insts.root.Position=pos
			end
			if size then
				self.insts.root.Size=size
			end
		end
	end
end
function M.InitAllButtons(self)
	self:AddProcess(function()
		for _, v in pairs(self.main_inst:GetDescendants()) do
			if v:IsA("GuiButton") then
				BtnHelper:InitButton(v, nil, nil, nil, function() end);
			end;
		end;
	end);
end
function M.new(...)
	return M(...);
end;
function M.ctor(self)
    InitInsts(self);
    M.super.ctor(self, ClientOHOH:GetPath_Loop("ReplicatedStorage.Resource.UI.SpinGui"));
    self:MobileSize();
    self:InitAllButtons();
    CallBackManager:AddRbxConnect(self,self.insts.Close.Activated, function()
        self:Hide();
	end);
    self.SpinFinishAction=ConnectClass.new();
end;
local TweenHelper = CommonOHOH.load.TweenHelper();
local tw1 = TweenInfo.new(3.4, Enum.EasingStyle.Quad,Enum.EasingDirection.Out);
function M.PlaySpin(self,rewardSettingStep)
    self.insts.Center.Rotation=0
    self:AddProcess(function()
        self:Wait()
        TweenHelper:PlayTween(self.insts.Center, tw1, {
            Rotation =3*360-(rewardSettingStep-1)*72,
        },function()
            self.SpinFinishAction:Action();
        end);
        for index, content in pairs(self.insts.content) do
            TweenHelper:PlayTween(content.CellFrame, tw1, {
                Rotation =-(3*360-(rewardSettingStep-1)*72),
            });
        end
    end)   
end
function M.FullRewardView(self,data)
	for k, v in pairs(data) do
        local content= self.insts.content[k];
        content.Icon.Visible=false;
        content.viewPort.Visible=false;
        if(v.icon) then
            content.Icon.Image=v.icon;
            content.Icon.Visible=true;
            elseif v.model then
                local old=content.viewPort:FindFirstChildOfClass("Model");
                    if old then
                        old:Destroy();
                    end

                    if v.model:IsA("Model") then 
                        v.model:SetPrimaryPartCFrame(content.CF.Value);
                        else
                            v.model.CFrame=content.CF.Value;    
                    end;
                
                v.model.Parent=content.viewPort;
                content.viewPort.Visible=true;                
        end
        --content.Name.Text=v.name .. "x" .. v.count;
        content.Name.Text="X".. BigNumberHelper:ToString(v.Nowcount);
        content.Probability.Text=v.weight .. "%";
    end;
end
function M.SetBuySpinBtnView(self,p1,c1,p2,c2)
    self.insts.LeftSpinBuyLable.Text=p1;
    self.insts.LeftSpinBuyCount.Text="x".. c1;

    self.insts.RightSpinBuyLable.Text=p2;
    self.insts.RightSpinBuyCount.Text="x" .. c2;
end;
function M.SetSpinBtnView(self,btnText,spinTimes)
    self.insts.SpinLable.Text=btnText;
    self.insts.SpinCount.Text="x"..spinTimes
end
function M.UpdateSpinInfo(self,timestr)
    self.insts.TimeCountDown.Text=LanguageHelper:GetText(10505,{"%%ARG1"},{timestr});
end;
function M.dtor(self)
	M.super.dtor(self);
end;

return M;